public class CalculateScore {
    private ReadPoints readPoints;
    private int firstPlayerPoints;
    private int secondPlayerPoints;
    public CalculateScore() {
        readPoints = new ReadPoints();
    }

    public String getScore(int firstPlayer, int secondPlayer) {
        firstPlayerPoints=firstPlayer;
        secondPlayerPoints=secondPlayer;
        if (hasWinner()) {
            if (firstPlayerPoints > secondPlayerPoints) {
                return "First player wins";
            } else return "Second player wins";

        } else if (deuce()) {

            return "Deuce";

        } else if (hasAdvantage()) {

            if (firstPlayerPoints > secondPlayerPoints) {
                firstPlayerPoints=4;
                secondPlayerPoints=5;
            } else {
                firstPlayerPoints=5;
                secondPlayerPoints=4;
            }

        } else if (firstPlayerPoints == secondPlayerPoints) {
            return readPoints.convert(firstPlayerPoints) + " all";
        }
        return readPoints.convert(firstPlayerPoints) + "/" + readPoints.convert(secondPlayerPoints);
    }

    public boolean hasWinner() {

        if (firstPlayerPoints >= 4 && firstPlayerPoints >= secondPlayerPoints + 2)
            return true;
        if (secondPlayerPoints >= 4 && secondPlayerPoints >= firstPlayerPoints + 2)
            return true;
        return false;

    }

    public boolean deuce() {
        return firstPlayerPoints >= 3  && secondPlayerPoints == firstPlayerPoints;
    }

    public boolean hasAdvantage() {

        if (secondPlayerPoints >= 4 && secondPlayerPoints == firstPlayerPoints + 1)
            return true;
        if (firstPlayerPoints >= 4 && firstPlayerPoints == secondPlayerPoints + 1)
            return true;
        return false;

    }


}